﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLO;
using Microsoft.Reporting.WinForms;
using System.Diagnostics;

namespace QuanLyBanHang
{
    public partial class frmDoanhThu : Form
    {
        public frmDoanhThu()
        {
            InitializeComponent();
            this.reportViewer1.RefreshReport();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnTaoBC_Click(object sender, EventArgs e)
        {

        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cbbNhanVien.SelectedValue.ToString()))
            {
                MessageBox.Show("Bạn phải chọn nhân viên!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            LoadData();
        }

        private void frmDoanhThu_Load(object sender, EventArgs e)
        {
            for (int i = 1; i <= 12; i++)
            {
                cbbThang.Items.Add(i + "");
            }
            cbbThang.SelectedIndex = 0;
            Utility.ComboboxUlt.LoadData(new NhanVien_Blo().GetAllObject(), cbbNhanVien, new[] { "TenNV", "MaNV" }, "Chọn nhân viên");
            this.reportViewer1.RefreshReport();

            reportViewer1.LocalReport.ReportPath = "../../DoanhThuReport.rdlc";
            reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DoanhThuDs", new HoaDonBan_Blo().GetDoanhThu("NV2", 1).Tables[0]));
            reportViewer1.RefreshReport();
        }

        private decimal TinhTongDoanhThu(DataGridView dgv)
        {
            decimal tong = 0;
            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                if (dgv.Rows[i].Cells["TongTien"].Value == null)
                    return tong;
                tong += decimal.Parse(dgv.Rows[i].Cells["TongTien"].Value.ToString());
            }

            return tong;
        }

        private void reportViewer1_Load(object sender, EventArgs e)
        {
            //if (cbbNhanVien.SelectedValue == null || string.IsNullOrEmpty(cbbNhanVien.SelectedValue.ToString())) return;
            ReportDataSource reportDs = new ReportDataSource("DoanhThuDs", new HoaDonBan_Blo().GetDoanhThu("NV2", 1).Tables[0]);
            reportViewer1.ProcessingMode = ProcessingMode.Local;
            reportViewer1.LocalReport.DataSources.Add(reportDs);
            reportViewer1.LocalReport.Refresh();
        }
        private void LoadData()
        {

            string manv = cbbNhanVien.SelectedValue.ToString();

            int thang = int.Parse(cbbThang.SelectedItem.ToString());
            reportViewer1.LocalReport.ReportPath = "../../DoanhThuReport.rdlc";
            reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DoanhThuDs", new HoaDonBan_Blo().GetDoanhThu("NV2", 1).Tables[0]));
            reportViewer1.RefreshReport();
        }

    }
}
